package com.example.aoporder.service.impl;

import com.example.aoporder.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    private final Map<String, Integer> cart = new HashMap<>();

    @Override
    public void add(String pname, int number) {
        cart.merge(pname, number, Integer::sum);
        System.out.println("【业务】已添加 " + number + " 件 [" + pname + "] 到购物车");
    }

    @Override
    public void delete(String pname) {
        cart.remove(pname);
        System.out.println("【业务】已从购物车删除 [" + pname + "]");
    }

    @Override
    public int find(String pname) {
        return cart.getOrDefault(pname, 0);
    }
}